home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / customs / reginfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-15  |  3.2 KB  |  113 lines

  1. /*-
  2.  * reginfo.c --
  3.  *    Find out who's registered.
  4.  *
  5.  * Copyright (c) 1988, 1989 by the Regents of the University of California
  6.  * Copyright (c) 1988, 1989 by Adam de Boor
  7.  * Copyright (c) 1989 by Berkeley Softworks
  8.  *
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any non-commercial purpose
  11.  * and without fee is hereby granted, provided that the above copyright
  12.  * notice appears in all copies.  The University of California,
  13.  * Berkeley Softworks and Adam de Boor make no representations about
  14.  * the suitability of this software for any purpose.  It is provided
  15.  * "as is" without express or implied warranty.
  16.  *
  17.  */
  18. #ifndef lint
  19. static char *rcsid =
  20. "$Id: reginfo.c,v 1.8 89/11/14 13:46:15 adam Exp $ SPRITE (Berkeley)";
  21. #endif lint
  22.  
  23. #include    "customs.h"
  24. #include    <stdio.h>
  25. #include    <netdb.h>
  26. #include    <sys/time.h>
  27.  
  28. typedef struct {
  29.     char          *name;
  30.     long          avail;
  31.     long          rating;
  32.     long          arch;
  33.     long          numClients;
  34.     long          *clients;
  35. } Host;
  36.  
  37. main(argc, argv)
  38.     int        argc;
  39.     char    **argv;
  40. {
  41.     char              infoBuf[MAX_INFO_SIZE];
  42.     Host              *allHosts;
  43.     int                  i, j;
  44.     int                  numHosts;
  45.     char              *cp;
  46.     struct sockaddr_in    sin;
  47.     struct hostent    *he;
  48.  
  49.     if (Customs_Master(&sin) != RPC_SUCCESS) {
  50.     Customs_PError("Customs_Master");
  51.     printf("Couldn't find master\n");
  52.     exit(1);
  53.     }
  54.     he = gethostbyaddr(&sin.sin_addr, sizeof(sin.sin_addr), AF_INET);
  55.     printf ("Master Agent at ");
  56.     if (he == (struct hostent *)NULL) {
  57.     printf("%s\n", InetNtoA(sin.sin_addr));
  58.     } else {
  59.     printf ("%s\n", he->h_name);
  60.     }
  61.     
  62.     if (Customs_Info(&sin, infoBuf) != RPC_SUCCESS) {
  63.     Customs_PError("Customs_Info");
  64.     printf("Couldn't read registration info\n");
  65.     }
  66.     cp = infoBuf;
  67.     numHosts = *(int *)cp;
  68.     cp += sizeof(int);
  69.     allHosts = (Host *)malloc(numHosts * sizeof(Host));
  70.     for (i = 0; i < numHosts; i++) {
  71.     allHosts[i].name = cp;
  72.     cp += strlen(cp) + 1;
  73.     cp = Customs_Align(cp, char *);
  74.     allHosts[i].avail = *(long *)cp;
  75.     cp += sizeof(long);
  76.     allHosts[i].rating = *(long *)cp;
  77.     cp += sizeof(long);
  78.     allHosts[i].arch = *(long *)cp;
  79.     cp += sizeof(long);
  80.     allHosts[i].numClients = *(long *)cp;
  81.     cp += sizeof(long);
  82.     allHosts[i].clients = (long *)cp;
  83.     cp += allHosts[i].numClients * sizeof(long);
  84.     }
  85.     
  86.     for (i = 0; i < numHosts; i++) {
  87.     printf ("%s (arch = %d): ", allHosts[i].name, allHosts[i].arch);
  88.     if (allHosts[i].avail & AVAIL_DOWN) {
  89.         printf ("host down\n");
  90.     } else if (allHosts[i].avail & AVAIL_IDLE) {
  91.         printf ("not idle\n");
  92.     } else if (allHosts[i].avail & AVAIL_SWAP) {
  93.         printf ("not enough swap space\n");
  94.     } else if (allHosts[i].avail & AVAIL_LOAD) {
  95.         printf ("load average too high\n");
  96.     } else if (allHosts[i].avail & AVAIL_IMPORTS) {
  97.         printf ("too many imported jobs\n");
  98.     } else {
  99.         printf ("available (index = %d)\n", allHosts[i].rating);
  100.     }
  101.     printf ("\tclients: ");
  102.     if (allHosts[i].numClients != 0) {
  103.         for (j = 0; j < allHosts[i].numClients; j++) {
  104.         printf ("%s ", allHosts[allHosts[i].clients[j]].name);
  105.         }
  106.         putchar('\n');
  107.     } else {
  108.         printf ("ALL\n");
  109.     }
  110.     }
  111.     printf ("Last allocated: %s\n", allHosts[*(long *)cp].name);
  112. }
  113.